Skip to content

Conversation

makukha
Copy link
Contributor

@makukha makukha commented Oct 5, 2025

Merged code and docs from pydantic-file-secrets v0.4.4

@makukha
Copy link
Contributor Author

makukha commented Oct 5, 2025

@hramezani the PR is ready for review.

secrets = reduce(
lambda d1, d2: dict((*d1.items(), *d2.items())),
(self.load_secrets(p) for p in self.secrets_paths),
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also support nested directories using the nested delimiter e.g. a file path like db/password could be mapped to db__password, which would write that into a nested model db with field password.

            # Transform keys for nested delimiter support
            if self.secrets_nested_delimiter and self.secrets_nested_delimiter != os.sep:
                transformed_secrets = {}
                for key, value in secrets.items():
                    new_key = key.replace(os.sep, self.secrets_nested_delimiter)
                    transformed_secrets[new_key] = value
                secrets = transformed_secrets

I see that the docs state that this is already supported, so I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my implementation I added this, but don't really remember why 😅

Maybe it was to also support the nested delimiter within the secret name i.e. a secret file named db__password.

Copy link
Contributor Author

@makukha makukha Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, you mean the case of both nested directory and file name prefix. This is already supported: https://github.com/makukha/pydantic-settings/blob/c39546cbe742855b7c96f2f9b5bcc23e64f7e8f1/tests/test_source_nested_secrets.py#L130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants